package com.yjt.fresh.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yjt.fresh.R;
import com.yjt.fresh.adpater.AdpVpMyCoupon;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.fragment.FrgMyCouponAlready;
import com.yjt.fresh.fragment.FrgMyCouponNotYet;
import com.yjt.fresh.fragment.FrgMyCouponOverdue;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的优惠券
 *
 * @author mcc
 * @date 2018/6/17
 */

public class AtyMyCoupon extends BaseSimpleActivity {
    @BindView(R.id.vp_app_aty_my_coupon)
    ViewPager mVp;
    @BindView(R.id.rlAppAtyMyCouponBack)
    RelativeLayout mRlBack;
    @BindView(R.id.tvAppAtyMyCouponNotYet)
    TextView mTvNotYet;
    @BindView(R.id.vAppAtyMyCouponNotYet)
    View mVNotYet;
    @BindView(R.id.rlAppAtyMyCouponNotYet)
    RelativeLayout mRlNotYet;
    @BindView(R.id.tvAppAtyMyCouponAlready)
    TextView mTvAlready;
    @BindView(R.id.vAppAtyMyCouponAlready)
    View mVAlready;
    @BindView(R.id.rlAppAtyMyCouponAlready)
    RelativeLayout mRlAlready;
    @BindView(R.id.tvAppAtyMyCouponOverdue)
    TextView mTvOverdue;
    @BindView(R.id.vAppAtyMyCouponOverdue)
    View mVOverdue;
    @BindView(R.id.rlAppAtyMyCouponOverdue)
    RelativeLayout mRlOverdue;
    private int mShowColor;
    private int mNormalColor;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_my_coupon;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        mShowColor = getResources().getColor(R.color.color_43b624);
        mNormalColor = getResources().getColor(R.color.color_333333);
    }

    @Override
    protected void initEvent() {
        initVP();
        onClick();
    }

    private void initVP() {
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new FrgMyCouponNotYet());
        fragments.add(new FrgMyCouponAlready());
        fragments.add(new FrgMyCouponOverdue());
        AdpVpMyCoupon adpMyCoupon = new AdpVpMyCoupon(getSupportFragmentManager(), fragments);
        mVp.setAdapter(adpMyCoupon);

        mVp.addOnPageChangeListener(mOnPageChangeListener);
    }
    private void onClick() {
        mRlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mRlNotYet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mVp.setCurrentItem(0,true);
                notYetShow();
            }
        });

        mRlAlready.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mVp.setCurrentItem(1,true);
                alreadyShow();
            }
        });

        mRlOverdue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mVp.setCurrentItem(2,true);
                overdueShow();
            }
        });
    }

    private void notYetShow() {
        mTvNotYet.setTextColor(mShowColor);
        mVNotYet.setVisibility(View.VISIBLE);
        mTvAlready.setTextColor(mNormalColor);
        mVAlready.setVisibility(View.GONE);
        mTvOverdue.setTextColor(mNormalColor);
        mVOverdue.setVisibility(View.GONE);
    }

    private void alreadyShow() {
        mTvAlready.setTextColor(mShowColor);
        mVAlready.setVisibility(View.VISIBLE);
        mTvNotYet.setTextColor(mNormalColor);
        mVNotYet.setVisibility(View.GONE);
        mTvOverdue.setTextColor(mNormalColor);
        mVOverdue.setVisibility(View.GONE);
    }
    private void overdueShow(){
        mTvOverdue.setTextColor(mShowColor);
        mVOverdue.setVisibility(View.VISIBLE);
        mTvNotYet.setTextColor(mNormalColor);
        mVNotYet.setVisibility(View.GONE);
        mTvAlready.setTextColor(mNormalColor);
        mVAlready.setVisibility(View.GONE);
    }


    ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    notYetShow();
                    break;
                case 1:
                    alreadyShow();
                    break;
                case 2:
                    overdueShow();
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };
}
